home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / Hardware / FreeWheel / WheelMouse.c < prev    next >
C/C++ Source or Header  |  2000-03-12  |  2KB  |  100 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #include <exec/types.h>
  6.  
  7. #include <clib/exec_protos.h>
  8.  
  9. #include "WheelMouse.h"
  10.  
  11. char *WindowModeNames[]={"Window under pointer",
  12.                          "Active window",NULL };
  13.  
  14. char *ButtonModeNames[]={"Ignore",
  15.                          "Shift",
  16.                          "Shift + click",
  17.                          "Wheel depth arrange",
  18.                          "Shift + depth arrange",
  19.                          "Cycle screens",NULL};
  20.  
  21. BOOL WheelMouse_Handle(struct WheelMouseContext *wmc,unsigned long signals);
  22. void WheelMouse_Dispose(struct WheelMouseContext *wmc);
  23.  
  24.  
  25. void WheelMouse_Dispose(struct WheelMouseContext *wmc)
  26. {
  27.   if(wmc)
  28.   {
  29.     if(wmc->ReplyPort)
  30.       DeleteMsgPort(wmc->ReplyPort);
  31.     if(wmc->SigBit>-1)
  32.       FreeSignal(wmc->SigBit);
  33.     free(wmc);
  34.   }
  35. }
  36.  
  37.  
  38. struct WheelMouseContext *WheelMouse_Create()
  39. {
  40.   struct WheelMouseContext *wmc;
  41.   if(!(wmc=malloc(sizeof(struct WheelMouseContext))))
  42.     return(NULL);
  43.   memset(wmc,0,sizeof(struct WheelMouseContext));
  44.  
  45.   wmc->Dispose=WheelMouse_Dispose;
  46.   wmc->Handle=WheelMouse_Handle;
  47.  
  48.   wmc->WindowModeNames=WindowModeNames;
  49.   wmc->MMBModeNames=ButtonModeNames;
  50.   wmc->FourthButtonModeNames=ButtonModeNames;
  51.   wmc->MouseSpeedX=wmc->MouseSpeedY=100;
  52.   wmc->ClickToFront=FALSE;
  53.  
  54.   wmc->MainTask=FindTask(NULL);
  55.   if((wmc->SigBit=AllocSignal(-1))==-1)
  56.   {
  57.     wmc->Dispose(wmc);
  58.     return(NULL);
  59.   }
  60.   wmc->Signals=1<<wmc->SigBit;
  61.  
  62.   if(!(wmc->ReplyPort=CreateMsgPort()))
  63.   {
  64.     wmc->Dispose(wmc);
  65.     return(NULL);
  66.   }
  67.   return(wmc);
  68. }
  69.  
  70.  
  71. void AddIntAtomic(int *a,int v)
  72. {
  73.   *a+=v;  /* Make sure your compiler generates a single instruction
  74.              for this operation, i.e. add.l d0,(a0), and not
  75.              move.l (a0),d1   add.l d0,d1   move.l d1,(a0) */
  76. }
  77.  
  78.  
  79. BOOL WheelMouse_Handle(struct WheelMouseContext *wmc,unsigned long signals)
  80. {
  81.   int distance;
  82.   if(!(signals&wmc->Signals))
  83.     return(TRUE);
  84.  
  85.   while(distance=wmc->ScrollX)
  86.   {
  87.     distance=DoScroll(wmc,FREEHORIZ,distance);
  88.     AddIntAtomic(&wmc->ScrollX,-distance);
  89.   }
  90.  
  91.   while(distance=wmc->ScrollY)
  92.   {
  93.     distance=DoScroll(wmc,FREEHORIZ|FREEVERT,distance);
  94.     AddIntAtomic(&wmc->ScrollY,-distance);
  95.   }
  96.  
  97.   return(TRUE);
  98. }
  99.  
  100.